package com.gps.misc;

import com.appengine.utils.GsonUtils;
import com.appengine.utils.SavingAndLoadingCenter;
import com.datatypes.User;
import com.gps.track.GpsTrackingActivitySolo;
import com.sporteamws.MainMenu;
import com.sporteamws.R;
import com.sporteamws.SharedPref;

import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

@SuppressWarnings("deprecation")
public class ActivityCenter extends TabActivity {

	User user = null;
	private boolean startAct = false;
	boolean intentOn = false;
	LocationManager lm = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity);

		TabHost tabHost = getTabHost();
		user = SavingAndLoadingCenter.loadUser(SharedPref.facebookID, this);

		TabSpec spec = tabHost.newTabSpec("Activities");
		spec.setIndicator("Activities",
				getResources().getDrawable(android.R.drawable.ic_menu_agenda));

		Intent intent = new Intent(this, ActivityRecord.class);
		Bundle bundle = new Bundle();
		String usrStr = GsonUtils.ConvertUserToGsonString(user);
		bundle.putString("USER", usrStr);
		intent.putExtras(bundle);

		spec.setContent(intent);

		TabSpec friendsSpec = tabHost.newTabSpec("Friends");
		friendsSpec.setIndicator("Friends",
				getResources().getDrawable(R.drawable.coop));
		intent = new Intent(this, FriendsCenter.class);
		bundle = new Bundle();
		bundle.putString("USER", usrStr);
		intent.putExtras(bundle);

		friendsSpec.setContent(intent);

		tabHost.addTab(spec);
		tabHost.addTab(friendsSpec);
		
		lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
	}

	@Override
	protected void onPause() {
		super.onPause();
		startAct = true;
		if (!this.isFinishing()){
			lm.removeUpdates(SharedPref.lb);
		}

	}

	@Override
	protected void onResume() {
		super.onResume();
		
			lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 5, SharedPref.lb);
	

		if (SharedPref.returnToMainMenu && startAct)
			finish();
		else
			SharedPref.returnToMainMenu = true;
	}

}
